<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<body>
	<div class="course-div">
	<div class="course-left">
    	<div class="white-pink">
	    <h1>教程基本信息<span>请务必填写下列信息</span></h1>
	    <label>
	    	<span>教程名称：</span>
	    	<input id="name" type="text" name="name" placeholder="请填写教程名称" />
	    </label>
	    <label>
	    	<span>主图：</span>
	    	<div class="file-select">
	    		<input type="file" id="main_pic_file" name="file" onchange="uploadImage('main_pic_file')"/>
		    	<img id="main_pic" alt="主图" src="public/img/add-image.png" />
	    	</div>
	    </label>
	    <label>
	    	<span>备注：</span>
	    	<textarea id="remark" name="remark" maxlength="255" placeholder="请输入备注信息，最长255个字符" style="resize: none;"></textarea>
	    </label>
	    <label>
	    	<span>&nbsp;</span>
	    	<button onclick="submitCourse()" class="button blue" style="margin-bottom: 5px;">保存</button>
    		<button onclick="reset()" class="button gray">重置/清空</button> 
	    </label>
	    </div>
    </div>
	<div class="course-right">
		<script id="container" name="content" type="text/plain">
       		 这里写你的初始化内容
    	</script>
	</div>
	</div>
	
    
    
    
    
	<script src="public/sys_js/ueditor/ueditor.config.js" type="text/javascript"></script>
	<script src="public/sys_js/ueditor/ueditor.all.js" type="text/javascript"></script>
	<script src="public/sys_js/ajaxfileupload.js" type="text/javascript"></script>
	<!-- 实例化编辑器 -->
    <script type="text/javascript">
    	//如果时自定义上传文件必须要有此段代码
    	//-------begin---------
	    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
	    UE.Editor.prototype.getActionUrl = function(action) {
	        if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadimage') {
	            return 'http://localhost:/mybatis-test/file/uploadToAliOSSByuEditor';
	        } else if (action == 'uploadvideo') {
	            return 'http://a.b.com/video.php';
	        } else {
	            return this._bkGetActionUrl.call(this, action);
	        }
	    }
	    //------end------
        var ue = UE.getEditor('container',{
        	autoHeightEnabled: false,
        	initialFrameHeight:800,
        	initialFrameWidth:470
        });

	    function reset(){
	    	$.messager.confirm('确认','确定清空文档内容？',function(r){    
	    	    if (r){    
	    	    	ue.execCommand('cleardoc');
	    	    }    
	    	});  
	    }

	    var picId = '';
	    function uploadImage(id){
	    	if($('#'+id).val()==''){
	    		$.messager.alert('没有待上传的文件');
	    		return;
	    	}
	    	$.fileUpload(id,{},function(data){
	    		if(data.success){
	    			var path = data.obj.path;
	    			$('#main_pic').attr('src',path);
	    			picId = data.obj.id;
	    			$('#'+id).val('');
	    		}else{
	    			$.messager.alert(data.msg);
	    		}
	    	});
	    }

	    function submitCourse(){
	    	$.messager.confirm('确认','确认提交？',function(r){
	    	    if (r){
	    	    	if(picId==''){
	    	    		$.messager.alert('警告','尚未上传主图');
	    	    		return false;
	    	    	}
	    	    	var name = $('#name').val();
	    	    	if(name==''){
	    	    		$.messager.alert('警告','请输入教程名称');
	    	    		return false;
	    	    	}
	    	    	var remark = $('#remark').val();
	    	    	var html = ue.getContent();
	    	    	$.submitAjax('course/manage','POST',{
	    	    		name:name,
	    	    		remark:remark,
	    	    		context:html,
	    	    		picId:picId
	    	    	},function(data){
	    	    		alert(data);
	    	    	});
	    	    }else{
	    	    	alert(0);
	    	    }    
	    	});
	    }
    </script>
</body>